package customers.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import customers.dal.daointerface.CustomerDevelopDAO;
import customers.dal.dataobject.CustomerDevelopDO;
import customers.dal.dataobject.CustomerDevelopDO;
import customers.model.CustomerDevelopResp;
import customers.model.CustomerDevelop;
import customers.model.CustomerDevelop;

import customers.service.CustomerDevelopService;

public class CustomerDevelopServiceImpl implements CustomerDevelopService{
	
	@Autowired
	private CustomerDevelopDAO customerDevelopMapper;

	@Override
	public CustomerDevelopResp<CustomerDevelop> queryCustomerDevelopByMemberId(String memberId) {
		if(memberId == null)
			new CustomerDevelopResp("9001","会员不存在");
	
		CustomerDevelopDO customerDevelopDO = customerDevelopMapper.queryByMemberId(memberId);
		CustomerDevelop customerDevelop = po2Vo(customerDevelopDO);
		CustomerDevelopResp<CustomerDevelop> res = new CustomerDevelopResp<CustomerDevelop>();
		res.setBody(customerDevelop);
		res.setResultCode("0000");
		res.setResultMsg("查询成功");
		return res;
	}

	@Override
	public CustomerDevelopResp<CustomerDevelop> insertCustomerDevelop(CustomerDevelop customerDevelop) {
		CustomerDevelopDO customerDevelopDO = new CustomerDevelopDO();
		customerDevelopDO.setAge(customerDevelop.getAge());
		customerDevelopDO.setAnnualSalary(customerDevelop.getAnnualSalary());
		customerDevelopDO.setCommonAddress(customerDevelop.getCommonAddress());
		customerDevelopDO.setGender(customerDevelop.getGender());
		customerDevelopDO.setMarriageStatus(customerDevelop.getMarriageStatus());
		customerDevelopDO.setMemberId(customerDevelop.getMemberId());
		customerDevelopDO.setWork(customerDevelop.getWork());
		customerDevelopDO.setWorkYears(customerDevelop.getWorkYears());
		CustomerDevelopResp<CustomerDevelop> res = new CustomerDevelopResp<>();
		int a = customerDevelopMapper.insert(customerDevelopDO);
		if(a==1){
			res.setBody(customerDevelop);
			res.setResultCode("0000");
			res.setResultMsg("添加成功");
		}else{
			res.setResultCode("9999");
			res.setResultMsg("添加失败");
		}
		return res;
		
	}
	
	private CustomerDevelop po2Vo(CustomerDevelopDO customerDevelopDO){
		if(customerDevelopDO == null)
			return null;
		CustomerDevelop customerDevelop = new CustomerDevelop();
		customerDevelop.setAge(customerDevelopDO.getAge());
		customerDevelop.setAnnualSalary(customerDevelopDO.getAnnualSalary());
		customerDevelop.setCommonAddress(customerDevelopDO.getCommonAddress());
		customerDevelop.setGender(customerDevelopDO.getGender());
		customerDevelop.setMarriageStatus(customerDevelopDO.getMarriageStatus());
		customerDevelop.setWork(customerDevelopDO.getWork());
		customerDevelop.setWorkYears(customerDevelopDO.getWorkYears());
		customerDevelop.setMemberId(customerDevelopDO.getMemberId());
		
		return customerDevelop;
		
	}

}
